﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Aandelendelen.Daily;
using Aandelendelen.Obs;
using NLog;
namespace Aandelendelen
{
	public class BaseForm : Page
	{
		protected static Logger logger = LogManager.GetCurrentClassLogger();

		protected override PageStatePersister PageStatePersister
		{
			get
			{
				return new SessionPageStatePersister(this);
			}
		}

		protected override void OnLoad(EventArgs e)
		{
			this.CheckMaintenance();

//		this.CheckRefferer();

			this.DoDailyJobs();

			//no page is cached on the client!
			Response.Cache.SetNoStore();
			Response.Cache.SetCacheability(HttpCacheability.NoCache);

			base.OnLoad(e);
		}

		protected Userinfo Userinfo
		{
			get { return (Userinfo)Session["userinfo"]; }
		}

		private void CheckMaintenance()
		{
			string endTime = Obs.Maintenance.GetInstance().ToString();

			if (endTime.Length > 0)
				Response.Redirect("/Maintenance.aspx?end=" + endTime, true);
		}

		private void DoDailyJobs()
		{
			DailyJobs dailyJobs = DailyJobs.GetInstance();

			dailyJobs.Handle();
		}
	}
}